package com.ruoyi.web.controller.deal;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.deal.deal_service.domain.DealInfoService;
import com.ruoyi.deal.deal_service.service.IDealInfoServiceService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单和服务关联Controller
 *
 * @author zhezhi
 * @date 2022-10-06
 */
@RestController
@RequestMapping("/serviceinfo/serviceDeal")
public class DealInfoServiceController extends BaseController
{
    @Autowired
    private IDealInfoServiceService dealInfoServiceService;

    /**
     * 查询订单和服务关联列表
     */
    @PreAuthorize("@ss.hasPermi('serviceinfo:serviceDeal:list')")
    @GetMapping("/list")
    @ApiOperation("查询订单和服务关联列表")
    public TableDataInfo list(DealInfoService dealInfoService)
    {
        startPage();
        List<DealInfoService> list = dealInfoServiceService.selectDealInfoServiceList(dealInfoService);
        return getDataTable(list);
    }

    /**
     * 导出订单和服务关联列表
     */
    @PreAuthorize("@ss.hasPermi('serviceinfo:serviceDeal:export')")
    @Log(title = "订单和服务关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出订单和服务关联列表")
    public void export(HttpServletResponse response, DealInfoService dealInfoService)
    {
        List<DealInfoService> list = dealInfoServiceService.selectDealInfoServiceList(dealInfoService);
        ExcelUtil<DealInfoService> util = new ExcelUtil<DealInfoService>(DealInfoService.class);
        util.exportExcel(response, list, "订单和服务关联数据");
    }

    /**
     * 获取订单和服务关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('serviceinfo:serviceDeal:query')")
    @GetMapping(value = "/{dealId}")
    @ApiOperation("获取订单和服务关联详细信息")
    public AjaxResult getInfo(@PathVariable("dealId") Long dealId)
    {
        return AjaxResult.success(dealInfoServiceService.selectDealInfoServiceByDealId(dealId));
    }

    /**
     * 新增订单和服务关联
     */
    @PreAuthorize("@ss.hasPermi('serviceinfo:serviceDeal:add')")
    @Log(title = "订单和服务关联", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增订单和服务关联")
    public AjaxResult add(@RequestBody DealInfoService dealInfoService)
    {
        return toAjax(dealInfoServiceService.insertDealInfoService(dealInfoService));
    }

    /**
     * 修改订单和服务关联
     */
    @PreAuthorize("@ss.hasPermi('serviceinfo:serviceDeal:edit')")
    @Log(title = "订单和服务关联", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改订单和服务关联")
    public AjaxResult edit(@RequestBody DealInfoService dealInfoService)
    {
        return toAjax(dealInfoServiceService.updateDealInfoService(dealInfoService));
    }

    /**
     * 删除订单和服务关联
     */
    @PreAuthorize("@ss.hasPermi('serviceinfo:serviceDeal:remove')")
    @Log(title = "订单和服务关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dealIds}")
    @ApiOperation("删除订单和服务关联")
    public AjaxResult remove(@PathVariable Long[] dealIds)
    {
        return toAjax(dealInfoServiceService.deleteDealInfoServiceByDealIds(dealIds));
    }
}
